/**
 * JAVACC DEMO 1.0
 * @copy right apache company All rights reserved. 
 * @Package com.apache.rpc.service.plugins  
 */
package com.apache.rpc.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.rpc.entity.InterfaceRegister;
import com.apache.rpc.manager.InterfaceRegisterManager;

/**
 * description:  接口注册信息添加插件实现
 * @author Hou Dayu 创建时间：2014-12-9  
 * @Copyright(c)2014:
 */
public class InterfaceRegisterSavePlugin implements PluginConnector {

	private InterfaceRegisterManager interfaceRegisterManager;

	/**
	 * 获取接口注册信息功能实现.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity result = new ResultEntity();
		InterfaceRegister register = new InterfaceRegister();
		ParamsVo<InterfaceRegister> vo = new ParamsVo<InterfaceRegister>();
		register.setBeanId(String.valueOf(param.getParams("beanId")));
		register.setBeanName(String.valueOf(param.getParams("beanName")));
		register.setFlag(Validator.getDefaultStr(String.valueOf(param.getParams("flag")), "0"));
		register.setCallType(String.valueOf(param.getParams("callType")));
		register.setMethodName(String.valueOf(param.getParams("methodName")));
		register.setPort(String.valueOf(param.getParams("port")));
		register.setAddress(String.valueOf(param.getParams("address")));
		register.setTimestampCreate(System.currentTimeMillis());
		vo.setObj(register);
		String registerId = interfaceRegisterManager.saveInfo(vo);
		if (Validator.isNotNull(registerId)) {
			result.setEntity("接口信息添加成功");
		} else {
			result.setEntity("接口信息添加失败");
		}
		result.setResult("true");
		result.setMessage("接口调用成功");
		return result;
	}

	public void setInterfaceRegisterManager(InterfaceRegisterManager interfaceRegisterManager) {
		this.interfaceRegisterManager = interfaceRegisterManager;
	}

}
